﻿<UserControl x:Class="GraphLibrary.GraphControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:graphsharp="clr-namespace:GraphSharp.Controls;assembly=GraphSharp.Controls"
             xmlns:zoom="clr-namespace:WPFExtensions.Controls;assembly=WPFExtensions"
             xmlns:local="clr-namespace:GraphLibrary"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300"
             x:Name="root">
    
    <UserControl.Resources>
        <DataTemplate x:Key="demoTemplate" DataType="{x:Type local:DFAVertex}">
            <StackPanel Orientation="Vertical" Margin="5">
                <StackPanel Orientation="Horizontal" Margin="5">
                    <TextBlock x:Name="isstart" Text="&gt;" Visibility="Hidden"/>
                    <TextBlock Text="State "/>
                    <TextBlock Text="{Binding Path=id, Mode=OneWay}" Foreground="Black" />
                    <TextBlock x:Name="isfin" Text="&lt;" Visibility="Hidden"/>
                </StackPanel>
                <Expander IsExpanded="True">
                    <StackPanel Orientation="Horizontal" Margin="5">
                        <TextBlock Text="Desc.: "/>
                        <TextBlock Text="{Binding Path=description, Mode=OneWay}" Foreground="Black" />
                    </StackPanel>
                </Expander>
            </StackPanel>
            <DataTemplate.Triggers>
                <DataTrigger Binding="{Binding isStart}" Value="true">
                    <Setter TargetName="isstart" Property="Visibility"
                                Value="Visible" />
                </DataTrigger>
                <DataTrigger Binding="{Binding isFinish}" Value="true">
                    <Setter TargetName="isfin" Property="Visibility"
                                Value="Visible" />
                </DataTrigger>
            </DataTemplate.Triggers>
        </DataTemplate>
        
        <Style TargetType="{x:Type graphsharp:VertexControl}">
            <Setter Property="Canvas.ZIndex" Value="1" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type graphsharp:VertexControl}">
                        <Border BorderBrush="#FF007ACC"
                                    Background="WhiteSmoke"
							        BorderThickness="2"
							        CornerRadius="10,10,10,10"
                                    Padding="{TemplateBinding Padding}">
                                    <ContentPresenter Content="{TemplateBinding Vertex}" 
                                            ContentTemplate="{StaticResource demoTemplate}"/>
                                
                            <Border.Effect>
                                <DropShadowEffect BlurRadius="2" Color="#FF007ACC" 
                                                    Opacity="0.3" Direction="315"/>
                            </Border.Effect>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>


        <Style TargetType="{x:Type graphsharp:EdgeControl}">
            <Style.Resources>
                <ToolTip x:Key="ToolTipContent">
                    <StackPanel>
                        <TextBlock FontWeight="Bold" Text="Via rule symbol:"/>
                        <TextBlock Text="{Binding rule}"/>
                    </StackPanel>
                </ToolTip>
            </Style.Resources>
            <Setter Property="ToolTip.DataContext" Value="{Binding RelativeSource={RelativeSource Self},Path=Edge}" />
            <Setter Property="Canvas.ZIndex" Value="2" />
            <Setter Property="ToolTip" Value="{StaticResource ToolTipContent}"/>
        </Style>
    
    </UserControl.Resources>
    
    <Grid Background="WhiteSmoke">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Expander IsExpanded="True" Grid.Column="0" ExpandDirection="Right">
            <StackPanel Orientation="Vertical">
                <Label VerticalAlignment="Center" VerticalContentAlignment="Center"
                       FontFamily="Segoe UI" FontWeight="Bold" Margin="0,5,5,5"  
                        Content="Pick Layout Algorithm"/>
            <ComboBox ItemsSource="{Binding LayoutAlgorithmTypes}"
                          SelectedItem="{Binding Path=LayoutAlgorithmType, Mode=TwoWay}"
                          Width="Auto" Height="Auto" Margin="0,5,5,5"/>
                <Separator/>
                <Label Content="Graph Info" FontWeight="Bold" />
                <StackPanel Orientation="Horizontal" Margin="0,5,5,5">
                    <Label Content="Q = " FontWeight="Bold" />
                    <DataGrid ItemsSource="{Binding vertexStates}" BorderBrush="#FF007ACC" GridLinesVisibility="Horizontal" HorizontalGridLinesBrush="#FF007ACC" VerticalGridLinesBrush="#FF007ACC" SelectionMode="Single" IsReadOnly="{Binding isReadOnly}" BorderThickness="0,1,1,1"/>
                </StackPanel>
                <StackPanel Orientation="Horizontal" Margin="0,5,5,5">
                    <Label Content="Σ = " FontWeight="Bold" />
                    <Label Content="{Binding S}"/>
                </StackPanel>
                <StackPanel Orientation="Horizontal" Margin="0,5,5,5">
                    <Label Content="δ = " FontWeight="Bold" />
                    <DataGrid x:Name="deltaGrid" ItemsSource="{Binding Path=edgeTransitions}" AutoGenerateColumns="False" BorderBrush="#FF007ACC" GridLinesVisibility="Horizontal" HorizontalGridLinesBrush="#FF007ACC" VerticalGridLinesBrush="#FF007ACC" SelectionMode="Single" IsReadOnly="{Binding isReadOnly}" BorderThickness="0,1,1,1">
                        <DataGrid.Columns>
                            <DataGridTemplateColumn Header="rule" IsReadOnly="{Binding isReadOnly}">
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding rule}"/>
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
                            </DataGridTemplateColumn>

                            <DataGridTemplateColumn Header="source Id" IsReadOnly="{Binding isReadOnly}">
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding sourceId}"/>
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
                            </DataGridTemplateColumn>

                            <DataGridTemplateColumn Header="target Id" IsReadOnly="{Binding isReadOnly}">
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding targetId}"/>
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
                            </DataGridTemplateColumn>
                        </DataGrid.Columns>
                    </DataGrid>
                </StackPanel>
            </StackPanel>
        </Expander>
        <zoom:ZoomControl Grid.Column="1" Background="WhiteSmoke" ZoomBoxOpacity="0.5" Zoom="0.2">
                <local:DFAGraphLayout x:Name="graphLayout" Margin="10" 
                                        Graph="{Binding Path=Graph}"
                                        LayoutAlgorithmType="{Binding Path=LayoutAlgorithmType, Mode=OneWay}"
                                        OverlapRemovalAlgorithmType="FSA"
                                        HighlightAlgorithmType="Simple" Background="WhiteSmoke"/>
        </zoom:ZoomControl>

    </Grid>
</UserControl>
